<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<title>商品编辑</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link href="/node_modules/LobsterUIFrame/layuiadmin/layui/css/layui.css" rel="stylesheet" />
	<link href="/node_modules/LobsterUIFrame/layuiadmin/style/admin.css" rel="stylesheet" />
	<link href="/node_modules/LobsterUIFrame/layuiadmin/layui/css/modules/layui-icon-extend/iconfont.css"
		rel="stylesheet" />
	<script src="/node_modules/LobsterUIFrame/layuiadmin/layui/layui.js"></script>
</head>

<body>
	<div class="layui-fluid box">
		<form class="layui-form" lay-filter="formdata" id="formdata" name="formdata">
			<div class="layui-card">
				<div class="layui-card-body">

					<div class="layui-row">
						<div class="layui-col-xs12">
							<div class="layui-form-item">
								<label class="layui-form-label"><i style="color:red;">*&ensp; </i>商品名称</label>
								<div class="layui-input-block">
									<input type="text" class="layui-input" lay-verify="required" id="GoodsName"
										name="GoodsName" disabled/>
								</div>
							</div>
						</div>
					</div>

					<div class="layui-row">
						<div class="layui-col-xs12">
							<div class="layui-form-item">
								<label class="layui-form-label"><i style="color:red;">*&ensp; </i>产品规格</label>
								<div class="layui-input-block">
									<input type="text" class="layui-input" lay-verify="required" id="ProductSpec"
										name="ProductSpec" disabled/>
								</div>
							</div>
						</div>
					</div>

					<div class="layui-row">
						<div class="layui-col-xs12">
							<div class="layui-form-item">
								<label class="layui-form-label"><i style="color:red;">*&ensp; </i>商品库存</label>
								<div class="layui-input-block">
									<input type="text" class="layui-input" lay-verify="required|number" id="GoodsStock"
										name="GoodsStock" />
								</div>
							</div>
						</div>
					</div>

					<div class="layui-row">
						<div class="layui-col-xs6">
							<div class="layui-form-item">
								<label class="layui-form-label">市场价</label>
								<div class="layui-input-block">
									<input type="text" class="layui-input" lay-verify="number" id="GoodsMarketPrice"
										name="GoodsMarketPrice" />
								</div>
							</div>
						</div>
						<div class="layui-col-xs6">
							<div class="layui-form-item">
								<label class="layui-form-label">零售价格</label>
								<div class="layui-input-block">
									<input type="text" class="layui-input" lay-verify="number" id="GoodsRetailPrice"
										name="GoodsRetailPrice" />
								</div>
							</div>
						</div>
					</div>

					<div class="layui-row">
						<div class="layui-col-xs12">
							<div class="layui-form-item">
								<label class="layui-form-label">产品图</label>
								<div class="layui-input-block">
									<input type="hidden" id="GoodsSpecImg" name="GoodsSpecImg">
									<div class="layui-upload">
										<div class="layui-inline">
											<button type="button" class="layui-btn" id="btnUpload">选择图片</button>
										</div>
										<div class="layui-input-block" id="img1" style="margin-left: 0;">
										</div>
									</div>
								</div>
							</div>
						</div>
					</div>

					<div class="layui-form-item layui-hide">
						<input type="button" lay-submit lay-filter="btnSubmit" id="btnSubmit" value="确认">
					</div>
				</div>
			</div>
			<div class="layui-form-item layui-hide">
				<input type="button" lay-submit lay-filter="LAY-app-front-submit" id="LAY-app-front-submit" value="保存">
				<input type="button" lay-cancel lay-filter="LAY-app-front-cancel" id="LAY-app-front-cancel" value="取消">
				<input type="reset" id="LAY-app-form-reset" value="重置">
			</div>

			<div class="layui-form-item layui-hide">
				<input type="text" id="GoodsSpecDetailId" name="GoodsSpecDetailId" value="0" />
				<input type="text" id="GoodsId" name="GoodsId" value="0" />
				<input type="text" id="SpecCom" name="SpecCom" value="0" />
				<input type="text" id="SpecItemCom" name="SpecItemCom" value="0" />
			</div>
		</form>
	</div>
</body>

</html>
<script type="text/html" id="temp">
    <div class="imgdiv">
        <img src="{{d.img}}" style="height:100px;width:100px;" />
    </div>
</script>
<script>
	layui.config({
		base: '/node_modules/LobsterUIFrame/layuiadmin/' //静态资源所在路径
	}).extend({
		index: 'lib/index' //主入口模块
	});

	layui.define(['index', 'layer', 'form', 'element', 'table', 'upload', 'laytpl'], function () {
		var layer = layui.layer;
		var form = layui.form;
		var element = layui.element;
		var table = layui.table;
		var $ = layui.$;
		var admin = layui.admin;
		var setter = layui.setter;
		var upload = layui.upload;
		var laytpl = layui.laytpl;


		var controller = {
			data: {
				model: {},
				fun: null,
				mainsrc: '',
			},
			//初始化页面
			initpage: function () {
				var self = this;
				console.log(parent.modelData)
				self.data.model = parent.modelData;

				self.getUploadUrl(function () {
					self.initevent();
					self.initData()
				});
			},
			getbaseurl: function (fun) {
				var url = "/lowcode/APP20200616102057595/shop/?view=layui&fun=" + fun;
				return url;
			},
			//初始化事件
			initevent: function () {
				var self = this;
				parent.getResult = function (fun) {
					self.data.fun = fun;
					$("#btnSubmit").click();
				}
				form.on('submit(btnSubmit)', function (data) {
					console.log(data.field)
					self.data.fun(data.field);
				});
				upload.render({
					elem: "#btnUpload",
					before: function (obj) {
						layer.load();
					},

					url: self.data.uploadUrl,//1图片 2视频 3pdf 4office 5other
					data: {
					},
					done: function (res) {
						layer.closeAll('loading');
						if (res.code == 0) {
							$("#GoodsSpecImg").val(res.data.url)
							self.data.mainsrc = res.data.url
							self.inittemp();
						}
					}
				});

			},
			getUploadUrl: function (func) {
				var self = this;
				var url = this.getbaseurl("Mall.getuploadurl");
				admin.req({
					url: url,  //控制器名称，方法名称
					data: {},
					done: function (res) {
						console.log(res);
						self.data.uploadUrl = res.data.url + "&fileType=1";
						if (func) {
							func();
						}
					}
				});
			},

			//加载数据
			initData: function () {
				var self = this;
				if (self.data.model) {

					console.log(self.data.model)
					form.val("formdata", Object.assign({}, self.data.model));
					if (self.data.model.GoodsSpecImg) {
						self.data.mainsrc = self.data.model.GoodsSpecImg
						self.inittemp()
					}
				}
			},
			inittemp: function () {
				var self = this;

				var getTpl = temp.innerHTML
					, view = document.getElementById('img1');
				laytpl(getTpl).render({
					img: self.data.mainsrc
				}, function (html) {
					view.innerHTML = html;
					form.render();
				});

			},
		}

		/*
		* 入口
		*/
		controller.initpage();
	});

</script>